package com.hlkj.warboot.module_sys.entity.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hlkj.warboot.configurer.util.StrUtil;
import com.hlkj.warboot.module_sys.entity.RoleEntity;

import java.util.Arrays;
import java.util.List;

/**
 * @Description: 动态生成QueryWrapper<RoleEntity>对象
 * @Author: lixing
 * @Date: 2020/6/12 17:27
 */
public class RoleWrapper {
    public static QueryWrapper<RoleEntity> queryWrapper(RoleEntity entity) {
        QueryWrapper<RoleEntity> queryWrapper = new QueryWrapper<>();
        if (entity.baseCreateTimeStart != null) {
            queryWrapper.ge("create_time", entity.baseCreateTimeStart);
        }
        if (entity.baseCreateTimeEnd != null) {
            queryWrapper.le("create_time", entity.baseCreateTimeEnd);
        }
        if (StrUtil.isEffective(entity.getCreateUserAccount())) {
            queryWrapper.eq("create_user_account", entity.getCreateUserAccount());
        }
        if (StrUtil.isEffective(entity.getId())) {
            if (entity.getId().contains(",")) {
                List<String> ids = Arrays.asList(entity.getId().split(","));
                queryWrapper.in("id", ids);
            } else {
                queryWrapper.eq("id", entity.getId());
            }
        }
        if (StrUtil.isEffective(entity.getRoleName())) {
            queryWrapper.eq("role_name", entity.getRoleName());
        }
        if (entity.getActive() != null) {
            queryWrapper.eq("active", entity.getActive());
        }
        return queryWrapper;
    }
}
